#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：ITableData_chat8.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/3/1 17:44 
"""

from abc import ABC, abstractmethod

import pandas as pd


class DataFetcher(ABC):
	@abstractmethod
	def fetch_data(self) -> pd.DataFrame:
		pass


class DatabaseFetcher(DataFetcher):
	def __init__(self, connection_string):
		self.connection_string = connection_string

	def fetch_data(self) -> pd.DataFrame:
		# 从数据库获取数据的代码
		# 返回一个 DataFrame
		pass


class CSVFetcher(DataFetcher):
	def __init__(self, file_path):
		self.file_path = file_path

	def fetch_data(self) -> pd.DataFrame:
		# 从 CSV 文件获取数据的代码
		# 返回一个 DataFrame
		pass


class ExcelFetcher(DataFetcher):
	def __init__(self, file_path, sheet_name):
		self.file_path = file_path
		self.sheet_name = sheet_name

	def fetch_data(self) -> pd.DataFrame:
		# 从 Excel 文件获取数据的代码
		# 返回一个 DataFrame
		pass


class DataFetcherFactory:
	@staticmethod
	def create_fetcher(data_source, **kwargs) -> DataFetcher:
		if data_source == "database":
			return DatabaseFetcher(**kwargs)
		elif data_source == "csv":
			return CSVFetcher(**kwargs)
		elif data_source == "excel":
			return ExcelFetcher(**kwargs)
		else:
			raise ValueError("Unsupported data source")


# 使用数据库获取数据
database_fetcher = DataFetcherFactory.create_fetcher(
	"database", connection_string="your_connection_string"
)
database_data = database_fetcher.fetch_data()
print(database_data)

# 使用 CSV 文件获取数据
csv_fetcher = DataFetcherFactory.create_fetcher("csv", file_path="your_csv_file_path")
csv_data = csv_fetcher.fetch_data()
print(csv_data)

# 使用 Excel 文件获取数据
excel_fetcher = DataFetcherFactory.create_fetcher(
	"excel", file_path="your_excel_file_path", sheet_name="sheet1"
)
excel_data = excel_fetcher.fetch_data()
print(excel_data)
